package com.xce.order;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @ClassName ServiceOrderApplication
 * @Description TODO
 * @Author lld
 * @Date 2025/6/17 15:15
 * @Version 1.0
 */
@Slf4j
@EnableFeignClients   // 开启远程调用
@SpringBootApplication
public class ServiceOrderApplication implements ApplicationRunner {

    @Autowired
    private NacosConfigManager nacosConfigManager;
    public static void main(String[] args) {
        SpringApplication.run(ServiceOrderApplication.class);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ConfigService configService = nacosConfigManager.getConfigService();
        configService.addListener("service-order.yml", "DEFAULT_GROUP", new Listener() {
            @Override
            public Executor getExecutor() {
                return Executors.newFixedThreadPool(4);
            }

            @Override
            public void receiveConfigInfo(String s) {
                log.info("监听到变化：{}",s );
            }
        });
    }
}
